package cn.alm.springmvc01helloworld.controller;

import cn.alm.springmvc01helloworld.entity.User;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("test")
public class TestController {

    @GetMapping("handle01")
    public String handle01(String username, String password, Integer age, Boolean agree) {
        System.out.println("username: " + username);
        System.out.println("password: " + password);
        System.out.println("age: " + age);
        System.out.println("agree: " + agree);
        return "success";
    }

    @PostMapping("handle02")
    public String handle02(@RequestBody User user) {
        String username = user.getUsername();
        String password = user.getPassword();
        System.out.println("username: " + username);
        System.out.println("password: " + password);
        return "success";
    }

    @PostMapping("handle03")
    public String handle03(@RequestHeader("my-header") String myHeader) {
        System.out.println("myHeader: " + myHeader);
        return "success";
    }

    @PostMapping("handle04")
    public String handle04(HttpEntity<User> entity) {
        User body = entity.getBody();
        String username = body.getUsername();
        String password = body.getPassword();
        System.out.println("username: " + username);
        System.out.println("password: " + password);
        HttpHeaders headers = entity.getHeaders();
        List<String> strings = headers.get("my-header");
        for (String string : strings) {
            System.out.println(string);
        }
        return "success";
    }

}
